<%@page import="com.alibaba.fastjson.JSONObject" %>
<%@page import="com.alibaba.fastjson.JSONArray" %>
<%@ page language="java" import="java.util.*,com.Search.text,com.entity.*,com.dao.NarRateDao" pageEncoding="utf-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <base href="<%=basePath%>">

    <title>My JSP 'listPr.jsp' starting page</title>

    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">

    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
    <!--
        这里是按钮
    -->
    <%
        request.setCharacterEncoding("utf-8");  //处理中文代码
        String add = request.getParameter("add");
    %>
    <link rel="stylesheet" type="text/css"
          href="https://webmap1.bdimg.com/wolfman/static/common/css/bmap.min_8854cf5.css"/>
    <link rel="stylesheet" type="text/css"
          href="https://webmap1.bdimg.com/wolfman/static/common/pkg/index_b000206.css"/>
    <link rel="stylesheet" type="text/css"
          href="https://webmap1.bdimg.com/wolfman/static/common/widget/ui/prompt/prompt_5b31ddb.css"/>
    <link rel="stylesheet" type="text/css"
          href="https://webmap1.bdimg.com/wolfman/static/pano/widget/module/PoiSearchModule/PoiSearchModule_4889fbb.css"/>
    <script type="text/javascript">
        function Search() {
            var add = document.getElementById("sole-input").value;
            if (add != "" && add != "<%=add %>") {
                window.location.href = "servlet/listPrServlet?add=" + encodeURI(add);//使用get方法传送id号
            }
        }
    </script>

</head>

<body style="height: 100%; margin: 0">
<div id="searchbox" class="clearfix" style=" float: left; position: absolute; left: 0px; top: 0px;">
    <div id="searchbox-container">
        <div id="sole-searchbox-content" class="searchbox-content">
            <input id="sole-input" class="searchbox-content-common" type="text" name="word" autocomplete="off"
                   maxlength="256" placeholder="<%=add %>" value="">
            <div class="input-clear" title="清空" style="display: none;"></div>
            <!--<div class="searchbox-content-button right-button route-button loading-button" data-title="路线" data-tooltip="1">
            </div>-->
        </div>
    </div>
    <button id="search-button" data-title="搜索" data-tooltip="2" onclick="Search()"></button>
    <div id="toast-wrapper">
        <div id="toast">
            <img class="info-tip-img" src="https://map.baidu.com//wolfman/static/common/images/transparent.gif" alt="">
            <span class="info-tip-text"></span>
        </div>
    </div>
</div>
<div id="container" style="height: 100%"></div>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/echarts/dist/echarts.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/echarts-gl/dist/echarts-gl.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/echarts-stat/dist/ecStat.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/echarts/dist/extension/dataTool.min.js"></script>
<!--<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/echarts/map/js/china.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/echarts/map/js/world.js"></script>-->
<script type="text/javascript" src="http://api.map.baidu.com/api?v=3.0&ak=E4805d16520de693a3fe707cdc962045"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/echarts/dist/extension/bmap.min.js"></script>
<script type="text/javascript" src="./js/basis/basis_pian.js"></script>
<script type="text/javascript" src="./js/algorithm/CoordinateTransformation.js"></script>

<script type="text/javascript">
    var dom = document.getElementById("container");
    var myChart = echarts.init(dom);
    var app = {};
    option = null;
    <%
try{
request.setCharacterEncoding("utf-8");  //处理中文代码
String Json_len = request.getParameter("Json_len");
String [] Java_Json_len= Json_len.split(",");
int add_len = Integer.parseInt(Java_Json_len[0]);
int pt_roadaoi_len =  Integer.parseInt(Java_Json_len[1]);
int pt_aoi_len =  Integer.parseInt(Java_Json_len[2]);
String Jsonname = request.getParameter("Jsonname");
String add_l = request.getParameter("add_l");
System.out.println("这里是listPr。jsp");
System.out.println(Json_len);
System.out.println(add_len);
System.out.println(pt_roadaoi_len);
System.out.println(pt_aoi_len);
System.out.println(Jsonname);
System.out.println(add_l);
text Text = new text();
JSONObject[] Json_res = Text.JSON_res("["+Jsonname+"]");			//创建 Jsonname 的数组对象
String JSON_pt_aoi = Json_res[0].getString("pt_aoi");				//获取 Jsonname 数组中的 pt_aoi  是string
System.out.println("Json_res[0].getString(\"pt_aoi\") = "+Json_res[0].getString("pt_aoi"));

JSONObject[] JSON_pt_aoi_res = Text.JSON_res(JSON_pt_aoi);			//将上面的String pt_aoi 转换成 JSONObject pt_aoi

  NarRateDao narRateDao=new  NarRateDao();  //构造对象


  ArrayList  list_fond= narRateDao.listAllNarRate_fond(add);
  for(int y=0;y<list_fond.size();y++) {
               NarRate narRate_fond=(NarRate)list_fond.get(y);//提取范围内的数据
               String Content = narRate_fond.getContent();
               String Date = narRate_fond.getDate();
               String SpaceName = narRate_fond.getSpaceName();
               String Spacedescribe = narRate_fond.getSpacedescribe();
               String Spacecontent = narRate_fond.getSpacecontent();
               String NarTypeName = narRate_fond.getNarTypeName();
               String MatTypeName = narRate_fond.getMatTypeName();
               String bd_longtitude = narRate_fond.getSpacelongtitude();
               String bd_latitude = narRate_fond.getSpacelatitude();
               String TypeName = narRate_fond.getTypeName();
               String text = Content+"\t"+Date+"\t"+SpaceName+"\t"+Spacedescribe+"\t"+Spacecontent+"\t"+NarTypeName+"\t"+MatTypeName+"\t"+bd_longtitude+"\t"+bd_latitude+"\t"+TypeName;
               System.out.println("提取的测试文本："+text);
        }

  ArrayList  list= narRateDao.listAllNarRate();

for( int i = 0; i < JSON_pt_aoi_res.length ; i++ ){
    String pt_aoi_value_xg = JSON_pt_aoi_res[i].getString("value_xg");
    System.out.println(pt_aoi_value_xg);
    String scatter_res = "[";
    String place_name = null;
         for(int y=0;y<list.size();y++) {
               NarRate narRate=(NarRate)list.get(y);						//提取范围内的数据
               String bd_longtitude = narRate.getSpacelongtitude();
               String bd_latitude = narRate.getSpacelatitude();
               String point = "{ x:"+bd_longtitude+", y:"+bd_latitude+"}";
               if(Text.PointInPolygon(point, pt_aoi_value_xg)){
                   place_name = narRate.getSpaceName();
                   String content = narRate.getSpacecontent();
                   String nei_Date = narRate.getDate();
                   scatter_res = scatter_res +"{"+"\"name\":\""+content+"\", \"value\":["+bd_longtitude+", "+bd_latitude+",50,\""+nei_Date+"\"]}";
               }
        }
        scatter_res = scatter_res+"]";
        if(scatter_res.equals("[]")){
            scatter_res = "[0]";
        }
                           %>
    series.push(
        {
            name: '<%=place_name %>',
            type: 'scatter',
            coordinateSystem: 'bmap',
            data: <%=scatter_res %>,
            label: {
                formatter: '',
                position: 'right',
                show: false
            },
            itemStyle: {
                color: 'rgb(42, 50, 212)'
            },
            emphasis: {
                label: {
                    show: true
                }
            }
        }
    )
    <%
}
System.out.println("JSON_pt_aoi_res[0]:"+JSON_pt_aoi_res[0]);
System.out.println("JSON_pt_aoi_res.length"+JSON_pt_aoi_res.length);
%>
    var Jsonname =
    <%=Jsonname %>
    var add_l =
    <%=add_l %>
    var roadaois_res =
    <%=Json_res[0].getString("pt_roadaoi") %>
    var aoi_res = <%=Json_res[0].getString("pt_aoi") %>
        center = add_l['value'];
    zoom_index = add_l['bounds'] - 2;
    <%
    if ( pt_roadaoi_len != -1 || pt_aoi_len != -1 ){		//判断是否可能
        for( int i = 0 ; i < pt_roadaoi_len + 1 ; i++){							//路还没有写完  还没写完data的数据
    %>
    var roadaoi_res = [];
    var roadaoi = roadaois_res[<%=i %>]['value'];
    //console.log(roadaoi);
    for (i = 0; i < roadaoi.length; i++) {
        roadaoi_res.push(
            {
                coords: roadaoi[i]
            }
        )
    }
    series.push(
        {
            type: 'lines',
            coordinateSystem: 'bmap',
            polyline: true,
            data: roadaoi_res,
            silent: true,
            lineStyle: {
                color: 'rgb(76, 97, 214)',
                width: 4
            },
            //   progressiveThreshold: 500,
            //   progressive: 200
        }
    )
    <%
        }
        for( int i = 0 ; i < pt_aoi_len + 1 ; i++){								//面积的
    %>
    var aoi = aoi_res[<%=i %>];

    function renderItem_lisrPr_<%=i %>(params, api) {
        var coords = aoi['value'];
        var points = [];
        for (var i = 0; i < coords.length; i++) {
            points.push(api.coord(coords[i]));
        }
        var color = api.visual('color');

        return {
            type: 'polygon',
            shape: {
                points: echarts.graphic.clipPointsByRect(points, {
                    x: params.coordSys.x,
                    y: params.coordSys.y,
                    width: params.coordSys.width,
                    height: params.coordSys.height
                })
            },
            style: api.style({
                fill: color,
                stroke: echarts.color.lift(color)
            })
        };
    }

    series.push(
        {
            type: 'custom',
            coordinateSystem: 'bmap',
            renderItem: renderItem_lisrPr_<%=i %>,
            itemStyle: {
                opacity: 0.2
            },
            animation: false,
            silent: true,
            data: [0],
            z: -10
        }
    )
    <%
        }
    }else{		//没有路和线   坐标点出现点
    %>

    <%
    }
    %>
    <%
}catch(Exception e){
    System.out.println("e="+e);
}

%>

    option = {
        tooltip: tooltip,
        bmap: {
            center: center,
            zoom: zoom_index,
            roam: true,
            mapStyle: mapStyle,

        },
        series: series
    };
    //  );
    //});;
    //if (option && typeof option === "object") {
    myChart.setOption(option);
    //}
</script>
</body>
</html>
